

using HalconDotNet;
using ZRFCore.MachineVisionAlgorithm.Controls.ZrfWindowControl.Model;
using ZRFCore.MachineVisionAlgorithm.Controls.ZrfWindowControl.Path;
using ZRFCore.MachineVisionAlgorithm.ShapeMatching;

namespace Logtest
{
    public partial class Form1 : Form
    {
        ShapeMatching shapeMatching;
        public Form1()
        {
            InitializeComponent();
            zrf_hWindow1.ReadImg(@"C:\Users\ZRF\MVS\Data\Image_20220812092652537.bmp");
            //zrf_hWindow2.ReadImg(@"C:\Users\ZRF\MVS\Data\Image_20220606141056907.bmp");
            zrf_hWindow2.ReadImg(@"C:\Users\ZRF\MVS\Data\Image_20220812092708752.bmp");
            shapeMatching = new ShapeMatching();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            HRegion region = zrf_hWindow1.Rois[0].GetRegion();
            HOperatorSet.ReduceDomain(zrf_hWindow1.Image, region, out HObject imgReduce);
            shapeMatching.AngleStart = -180;
            shapeMatching.AngleExtent = 360;
            shapeMatching.CreateShapeMatchModel(new HImage(imgReduce));
            
        }

        private void button3_Click(object sender, EventArgs e)
        {
            zrf_hWindow1.DrawLine();
        }

        private void button7_Click(object sender, EventArgs e)
        {
            zrf_hWindow1.DrawRect1();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            zrf_hWindow1.DrawPoint();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            zrf_hWindow1.DrawCircle();
        }

        private void button6_Click(object sender, EventArgs e)
        {
            zrf_hWindow1.DrawCircularArc();
        }

        private void button8_Click(object sender, EventArgs e)
        {
            zrf_hWindow1.DrawRect2();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            List<List<IROI>> listRois = shapeMatching.FindAllRois(zrf_hWindow1.Rois, zrf_hWindow2.Image);
            zrf_hWindow2.Rois.Clear();
            for (int i = 0; i < listRois.Count; i++)
            {
                for (int j = 0; j < listRois[i].Count; j++)
                {
                    zrf_hWindow2.Rois.Add(listRois[i][j]);
                }
            }
            zrf_hWindow2.Repaint();
        }

        private void button9_Click(object sender, EventArgs e)
        {
            zrf_hWindow1.DrawXldPathPoint();
        }

        private void button10_Click(object sender, EventArgs e)
        {
            zrf_hWindow1.DrawXldPathLine();
        }

        private void button11_Click(object sender, EventArgs e)
        {
            zrf_hWindow1.DrawXldPathCircularArc();
        }

        private void button12_Click(object sender, EventArgs e)
        {
            List<List<XldPath>> listXldPaths = shapeMatching.FindAllXldPaths(zrf_hWindow1.XldPaths, zrf_hWindow2.Image);
            zrf_hWindow2.XldPaths.Clear();
            for (int i = 0; i < listXldPaths.Count; i++)
            {
                for (int j = 0; j < listXldPaths[i].Count; j++)
                {
                    zrf_hWindow2.XldPaths.Add(listXldPaths[i][j]);
                }
            }
            zrf_hWindow2.Repaint();
        }
    }
}